/*
 * @Author: Zhang Yingying
 * @Date: 2020-10-27 10:23:46
 * @LastEditors: Zhang Yingying
 * @LastEditTime: 2020-11-07 21:50:42
 */
import BaseApi from './BaseApi'
export default class BaseCrudApi extends BaseApi {
  constructor(controller, action) {
    super(controller)
    this.action = action
    this.path = `${this.controller}/${this.action}`
  }

  setPath(path) {
    this.path = path
  }

  create(model) {
    return this.http({
      method: 'PUT',
      url: this.path,
      data: model,
      headers: {
        'Content-Type': 'application/json',
      },
    })
  }

  update(model) {
    return this.http({
      method: 'POST',
      url: this.path,
      data: model,
      headers: {
        'Content-Type': 'application/json',
      },
    })
  }

  remove(id) {
    return this.http({
      method: 'DELETE',
      url: `${this.path}/${id}`,
    })
  }

  removeAll(ids) {
    return this.http({
      method: 'DELETE',
      url: this.path,
      params: {
        ids,
      },
    })
  }

  getAll() {
    return this.http({
      method: 'GET',
      url: this.path,
    })
  }

  get(id) {
    return this.http({
      method: 'GET',
      url: `${this.path}/${id}`,
    })
  }
}
